<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
    <script src="js/axios.js"></script>
</head>
<body>
    <div class="app">
        <input type="text" placeholder="输入用户名" v-model.trim.lazy="username">
        <!-- <input type="submit" value="注册"> -->
    </div>
    <script>
        const vm = new Vue({
            el: '.app',
            data:{
                username: "",
            },
            watch:{
                username(newVal,oldVal){
                    if(newVal === ''){
                        return
                    }else{
                        axios({
                            method: 'get',
                            url: "https://www.escook.cn/api/finduser/" + newVal,
                            
                        }).then(function(res){
                            if(res.status === 200){
                                console.log('用户名可用')
                            }else{
                                console.log("用户名不可用")
                            }
                            // console.log(res.status)
                        })
                    }
                }
            }
        })
    </script>
</body>
</html>